/*
 * @Author: 胡海
 * @Date: 2020-02-21 18:23:26
 * @LastEditors: 胡海
 * @LastEditTime: 2020-03-07 21:17:44
 * @Description: 
 */
const {
    sequelize
} = require('../../core/db.js')


const {
    Sequelize,
    Model,
    Op
} = require('sequelize')

// define
class BuyOrder extends Model {
    static async addBuyOrder(ctx, v) { // 添加订单
        let request = {
            orderSum: v.orderSum,
        }
        BuyOrder.create(request)
    }
    static async list(ctx, v) { // 列表
        let request = {
            count: v.get('body.count'),
            start: v.get('body.start'),
        }
        const total = await BuyOrder.count()
        const list = await BuyOrder.findAll({
            order: [
                ['id']
            ],
            limit: request.count,
            offset: (request.start - 1) * request.count
        })
        const data = {
            list,
            total
        }
        return data
    }
}

BuyOrder.init({
    orderSum: Sequelize.INTEGER,
}, {
    sequelize,
    tableName: 'buyOrder',
    alter: true
})

module.exports = {
    BuyOrder
}

// 数据迁移 SQL 更新 风险